<!DOCTYPE>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>增加支点</title>
    <link rel="stylesheet" href="/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/jquery.validation/1.14.0/jquery.validate.min.js"></script>
    <script src="/js/jquery.validation/1.14.0/messages_zh.min.js"></script>

    <style>
        input.error {
            border: 1px solid #E6594E;
        }
    </style>
</head>
<body>
<script src="/js/webSocket.js"></script>

                    <div class="container">
                        <form id="addBranchForm">
                            <br />
                            <div class="form-group">
                                <label for="bname">支点名称：</label> <input type="text"
                                                                     class="form-control" id="bname" name="bname" placeholder="输入支点名称">
                            </div>
                            <div class="form-group">
                                <label for="btelephone">支点电话：</label> <input type="text"
                                                                         class="form-control" id="btelephone" name="btelephone"
                                                                         placeholder="输入支点电话">
                            </div>
                            <div class="form-group">
                                <label for="bcity">所在城市：</label> <input type="text"
                                                                      class="form-control" id="bcity" name="bcity" placeholder="输入支点所在城市">
                            </div>
                            <div class="form-group">
                                <label for="blocation">详细信息：</label> <input type="text"
                                                                     class="form-control" id="blocation" name="blocation" placeholder="输入详细信息">
                            </div>
                            <div class="form-group">
                                <label for="uname">负责人：</label> <input type="text"
                                                                      class="form-control" id="uname" name="uname" placeholder="输入负责人">
                            </div>
                            <div class="form-group">
                                <label for="phone">负责电话：</label> <input type="text"
                                                                       class="form-control" id="phone" name="phone" placeholder="输入负责人电话">
                            </div>
                            <div class="form-group">
                                <label for="blongitude">经度：</label> <input type="text" class="form-control"
                                                                    id="blongitude" name="blongitude" placeholder="输入位置的经度">
                            </div>
                            <div class="form-group">
                                <label for="bdimension">维度：</label> <input type="text" class="form-control"
                                                                         id="bdimension" name="bdimension" placeholder="输入位置的维度">
                            </div>
                            <div class="form-group">
                                <label for="bdesc">备注：</label> <input type="text" class="form-control"
                                                                         id="bdesc" name="bdesc" placeholder="输入备注">
                            </div>
                            <div class="form-group">
                                <button type="button" id="saveBtn" class="btn btn-success">提交</button>
                                <button type="button" id="cancelBtn" class="btn btn-default">取消</button>
                            </div>
                        </form>
                    </div>

</body>
</html>

<script type="text/javascript">
var addBranch=function () {
    if(!check().form()){
        return;
    }
    $.ajax({
        type:"POST",
        url:"/branch/add",
        contextType:"application/json",
        data:$("#addBranchForm").serialize(),
        success:function () {
            $("#cancelBtn").click();
        }
    });
}
var flag;
var getEmpByUname=function(){
    $.ajax({
        type:"GET",
        async:false,
        url:"/branch/findEmpByUname",
        data:{
            uname:$("#uname").val()
        },
        contentType:"application/json",
        success:function (msg) {
            /*var arrList=msg;*/
            if(msg.length>0){
                flag="true";
                if(msg.length==1){
                    alert(msg[0].empPhone);
                    $("#phone").val(msg[0].empPhone);
                }
            }else {
               flag="false";
            }
        }
    });
}

$("#uname").blur(function () {
    getEmpByUname();
   /* alert(flag);*/
    if(flag=="false"){
        alert("该名员工信息不存在,请重新填写!");
        /*$("#uname").css("color",red).val("该名员工信息不存在,请重新填写!");
        document.getElementById("uname").placeholder="该名员工信息不存在,请重新填写!";
       layer.msg("不存在该员工的信息,请重新填写",{icon:6,time:1000});*/
    }

});

$("#cancelBtn").click(function () {
    var index=parent.layer.getFrameIndex(window.name);
    parent.getBranchList();
    parent.layer.close(index);
});
$("#saveBtn").click(function () {
    addBranch();
});　
function check() {
    return $("#addBranchForm").validate({
        rules:{
            bname:{
                required:true
            },
            btelephone:{
                required:true
            },
            bcity:{
                required:true
            },
            blocation:{
                required:true
            },
            uname:{
                required:true
            },
            phone:{
                required:true

            },
            blongitude:{
                required:true
            },
            bdimension:{
                required:true
            },
            bdesc:{
                required:true
            },
            quarter1:{
                required:true
            },
            quarter2:{
                required:true
            },
            quarter3:{
                required:true
            },
            quarter4:{
                required:true
            }

        },
        messages:{
            bname:{
                required:""
            },
            btelephone:{
                required:""
            },
            bcity:{
                required:""
            },
            blocation:{
                required:""
            },
            uname:{
                required:""
            },
            phone:{
                required:""
            },
            blongitude:{
                required:""
            },
            bdimension:{
                required:""
            },
            bdesc:{
                required:""
            },
            quarter1:{
                required:""
            },
            quarter2:{
                required:""
            },
            quarter3:{
                required:""
            },
            quarter4:{
                required:""
            }

        }
    });
}
</script>